package com.zunipe.minix;

import com.zunipe.until.Util;
import net.minecraft.client.util.Session;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Session.class)
public class SessionMixin
{
    @Inject(method = "<init>", at = @At("RETURN"))
    private void init(String username, String uuid, String accessToken, String accountType, CallbackInfo info)
    {
        Util.username = username;
        Util.accessToken = accessToken;
        Util.uuid = uuid;
    }

    @Inject(method = "getSessionId", at = @At("HEAD"), cancellable = true)
    private void getSessionId(CallbackInfoReturnable<String> info)
    {
        info.setReturnValue("token:" + Util.accessToken + ":" + Util.uuid);
    }

    @Inject(method = "getUuid", at = @At("HEAD"), cancellable = true)
    private void getUuid(CallbackInfoReturnable<String> info)
    {
        info.setReturnValue(Util.uuid);
    }

    @Inject(method = "getUsername", at = @At("HEAD"), cancellable = true)
    private void getUsername(CallbackInfoReturnable<String> info)
    {
        info.setReturnValue(Util.username);
    }

    @Inject(method = "getAccessToken", at = @At("HEAD"), cancellable = true)
    private void getAccessToken(CallbackInfoReturnable<String> info)
    {
        info.setReturnValue(Util.accessToken);
    }
}
